<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>添加</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all"/>
    <script src="/layuiadmin/layui/layui.js"></script>
</head>
<body style="background-color:#fff">

<div class="layui-card">
    <div class="layui-card-body">
        <form class="layui-form" action="" class="layui-form layui-form-pane" lay-filter="layui-form-pane" id="sbumitForm">

            <div class="layui-form-item">
                <label class="layui-form-label">视频标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" value="{$model->title}" lay-verify="required" id="input_title" class="layui-input" placeholder="视频标题" autocomplete="off">
                </div>
            </div>
            <!--
            <div class="layui-row layui-col-space10 layui-form-item">
                <label class="layui-form-label">封面图片</label>
                <div class="layui-input-inline">
                    <input name="cover" lay-verify="required" id="cover" placeholder="请上传封面或输入封面地址" value="{$model->cover}" class="layui-input" autocomplete="off">
                </div>
                <div class="layui-input-inline layui-btn-container" style="width: auto;">
                    <button type="button" class="layui-btn layui-btn-primary" id="Upload_cover">
                        <i class="layui-icon">&#xe67c;</i>上传图片
                    </button>
                    <span class="layui-btn layui-btn-primary" onclick="icon_view('cover')">查看图片</span>
                </div>
            </div>-->
            <div class="layui-form-item">
                <label class="layui-form-label">视频类型</label>
                <div class="layui-input-block">
                    <select name="type" lay-verify="required">
                        <option value="">请选择</option>
                        <?php foreach($types as $key => $value) {?>
                        <option value="{$key}" <?php if($model->type == $key){echo 'selected';} ?>>{$value}</option>
                        <?php }?>
                    </select>
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">点赞次数</label>
                <div class="layui-input-block">
                    <input type="text" name="like_count" value="{$model->like_count}"  class="layui-input" placeholder="点赞次数" autocomplete="off">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">观看次数</label>
                <div class="layui-input-block">
                    <input type="text" name="play_count" value="{$model->play_count}"  class="layui-input" placeholder="观看次数" autocomplete="off">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <input type="text" name="remark" value="{$model->remark}"  class="layui-input" placeholder="备注" autocomplete="off">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">视频状态</label>
                <div class="layui-input-block">
                    <input type="radio" value="1" name="status" title="上架" {eq name="$model->status" value="1" }checked{/eq} />
                    <input type="radio" value="2" name="status" title="下架" {eq name="$model->status" value="2" }checked{/eq} />
                </div>
            </div>

            <!---
            <div class="layui-form-item">
                <label class="layui-form-label">是否热门</label>
                <div class="layui-input-block">
                    <input type="radio" value="1" name="is_hot" title="是" {eq name="$model->is_hot" value="1" }checked{/eq} />
                    <input type="radio" value="0" name="is_hot" title="否" {eq name="$model->is_hot" value="0" }checked{/eq} />
                </div>
            </div>-->

            <div class="layui-form-item">
                <label class="layui-form-label">横/竖 屏</label>
                <div class="layui-input-block">
                    <input type="radio" value="1" name="direction" title="竖屏" {eq name="$model->direction" value="1" }checked{/eq} />
                    <input type="radio" value="0" name="direction" title="横屏" {eq name="$model->direction" value="0" }checked{/eq} />
                </div>
            </div>

            <div class="layui-form-item" style="margin-top: 35px">
                <div class="layui-input-block">
                    <span class="layui-btn"  lay-submit="" lay-filter="submitForm" style="width: 100%">确认修改</span>
                </div>
            </div>
        </form>
    </div>
</div>

<script>
    layui.use(['form', 'upload'], function () {
        $ = layui.jquery;
        var form = layui.form, layer = layui.layer, upload = layui.upload;
        upload.render({
            elem: '#Upload_cover',
            auto: false,
            accept: 'images',
            exts: 'svg|png|jpg|jpeg|gif|webpg',
            size: 1024 * 1024,
            choose: function (obj) {
                layer.load();
                obj.preview(function (index, file, result) {
                    var FromData = new FormData();
                    FromData.append("image", file);
                    $.ajax({
                        type: "POST", //请求方式
                        url: '{$video_upload_url}/index/img', //请求地址
                        dataType: "json", //返回的数据类型
                        data:FromData,
                        processData: false,
                        contentType: false,
                        //请求成功
                        success: function (data) {
                            if (data.code == 0) {
                                layer.msg('上传成功', {icon: 1, time: 2000});
                                $("#cover").val(data.results.url);
                            } else {
                                layer.msg(data.message, {icon: 5});
                            }
                            layer.closeAll('loading');
                        },
                        //请求失败
                        error: function (e) {
                            layer.closeAll('loading');
                            layer.msg('上传出现异常,请稍后再试', {icon: 2});
                        }
                    });
                });
                document.getElementById("sbumitForm").reset();
            }
        });

        form.on('submit(submitForm)', function (obj) {
            layer.confirm('确认要修改吗？', {icon: 6}, function () {
                $.ajax({
                    type: "POST", //请求方式
                    url: '/admin/video/edit?id={$model->id}', //请求地址
                    dataType: "json", //返回的数据类型
                    data: $("#sbumitForm").serialize(), //数据
                    //请求成功
                    success: function (data) {
                        if (data.code == 0) {
                            layer.msg(data.msg, {icon: 1, time: 2000}, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                                window.parent.location.reload();
                            });
                        } else {
                            layer.msg(data.msg, {icon: 2, time: 5000});
                        }
                    }
                });
            });
            return false;
        });
    });

    function icon_view(id) {
        if (document.getElementById(id).value) {
            layer.photos({
                photos: {
                    "title": "",
                    "data": [{
                        "src": "{$video_play_url}" + document.getElementById(id).value,
                    }]
                }
                , shade: 0.01
                , closeBtn: 1
            });
        }
    }

</script>
</body>

</html>
